#!/usr/bin/python
# -*- coding: UTF-8 -*-
# @Time    : 2018/1/24 15:17
# @Author  : RNone
import sys
import excel_control


def main():
    '''读取用例配置'''
    ec = excel_control.excel_control()  # 实例化xls操作类
    confKeys = []  # 初始化用例标题列表
    casesSheet = ec.excel_read('.\\test_cases.xls')  # 读取xls文件
    for row in range(0, casesSheet.nrows):  # 循环遍历每一行数据
        caseList = casesSheet.row_values(row)  # 将每一行数据取出
        if row == 0:  # 将首行变量名取出
            confKeys = caseList  # 赋值给用例标题列表
        else:
            caseDict = ec.case_to_dict_from_cases(confKeys, caseList)  # 将用例参数取出，并用变量名匹配
            params = caseDict['params']
            __import__(caseDict['module'])  # 动态导入需要的模块
            moudle = sys.modules[caseDict['module']]  # 实例化模块
            c = getattr(moudle, caseDict['module'])  # 根据参数导入需要的类
            obj = c()  # 实例化类
            func = getattr(obj, caseDict['function'])  # 根据参数导入需要的方法
            result = func(params)  # 执行方法，并将参数传入
            ec.excel_revise('.\\test_cases.xls', row, confKeys.index('result'), result)


if __name__ == '__main__':
    main()
